<?php
// $Id: results.tpl.php,v 1.5 2007/10/11 09:51:29 goba Exp $
global $base_url,$language;
  $url = $base_url . '/' . drupal_get_path('module', 'documents');
//print_r($language);
//print "<pre>";print_r($items); print"</pre>";
  if($language->language=='ta'){
	$lang= '/ta';
}else{
 $lang='';
}

?>
	 <div class="view-header" id="viewmod_documents_<?php print $language->language?>">
		<div class="inner_tab_content">
			<div class = "inner_li"><a class="view_head_sel active" href="<?php print $base_url.$lang?>/documents/deptname"><?php print t('Department wise')?></a></div>		   	
			<div class = "inner_li"><a class="view_head_nonsel" href="<?php print $base_url.$lang?>/documents/category"><?php print t('Category wise')?></a></div>	
        	 <div class = "inner_li"><?php if($language->language=='en'){?><a class="view_head_nonsel" href="<?php print $base_url.$lang?>/documents/atoz"><?php print t(' A to Z')?></a><?php }?></div>		
		    <div class = "inner_li"><a class="view_head_nonsel" href="<?php print $base_url.$lang?>/documents/search"><?php print t('Search')?></a></div>
		</div>
		
	<div class="result_inner">
		<div>
		<?php  foreach($items as $row){?>
		<?php $dep = $row->field_department['und'][0]['value'];
		my_db_change(1);
				$qury = db_query("select n.dept_name from depart_mst AS n where dep_id = '$dep'");
				foreach($qury  as $key){	
				//print_r($qury);			
					 $depname = $key->dept_name; 
				}
				my_db_change(0);
		?>
		<?php } ?>
		<?php if($depname != ''){?>
		<div class="res_dept"><span >
			<strong><?php echo t($depname)?></strong></span>
		<?php } ?>
			<span style="float:right;margin-right:23px;">
			<a href="<?php print $base_url.$lang;?>/documents/deptname"><?php print t('Back')?></a></span>
		</div>
		
		<?php 
		$i=0;           
		 foreach($items as $row){
		 if ($row->field_doctype['und'][0]['value'] == 'online') {
			$link =  $row->field_docupload['und'][0]['value'];
		}
		else if($row->field_doctype['und'][0]['value'] == 'download') {
		     $link = $row->field_docupload['und'][0]['uri'];		
		    $wrapper = file_stream_wrapper_get_instance_by_uri($link);
			if($wrapper == true){
				 $pathfile = $wrapper->getDirectoryPath() . "/" . file_uri_target($link);
			}
			  $link="'http://cms.tn.gov.in/tncms_latest/$pathfile'";
		}
		if ($row->field_docupload['und'][0]['filesize'] != '0') {
			$kb = ceil($row->field_docupload['und'][0]['filesize']/1024);
			$kbyte= $kb.KB;
			if($kb >1024) { 
			  $kb = ceil($kb/1024);
			  $kbyte= $kb.MB;
			}
		}
		?>
			<div class="res_title_ch" style="">
				 <p><a onclick="return tnportal_window(<?php print $link ?>);" href="javascript:void(0);" >
						<?php echo  ucfirst(t($row->title)) ?>  <img alt="Download Icon" src="http://cms.tn.gov.in/sites/default/files/icons/pdf_icon.gif">
						<span class="kb">
							<span>(<?php print $kbyte?>)</span>
						</span>		
					</a>
				 </p>
			</div>			
		<?php $i++; } ?>
		<?php if($i == '0'){?>
			 <div class="no_record">No Results Found </div>
		<?php }	?>
	</div>
<div class="clr"></div>
</div>